const fs = require('fs')

const base64Encode = (file) => {
  let bitmap = fs.readFileSync(file)
  return new Buffer(bitmap).toString('base64')
}

const base64Decode = (base64str, file) => {
  let bitmap = new Buffer(base64str, 'base64')
  let len = Buffer.byteLength(bitmap, 'utf8')

  fs.writeFileSync(file, bitmap)
  console.log(' >> file has been created from encode string ... ')
  console.log(' >> filesize: ' + (len / 1024) + 'kb')
  return len
}

module.exports = {
  base64Encode,
  base64Decode
}
